package com.dy.nygl.controller;


import java.util.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dy.nygl.pojo.Department;
import com.dy.nygl.service.DepartmentService;

@Controller
@RequestMapping("/department")
public class DepartmentController {

	@Resource(name="departmentService")
	private DepartmentService departmentService;
	
	@RequestMapping("/getDepartment.action")
	@ResponseBody    
	public List<Map<String, Object>> getDepartment(HttpServletResponse response) {		
		response.setContentType("text/html;charset=utf-8");
		
		List<Department> departList = departmentService.getDepartment();
		
		if(departList != null) {
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			for(int i=0; i<departList.size(); i++) {
				Map<String, Object> map = new LinkedHashMap <String, Object>();
				map.put("id",departList.get(i).getId());
				map.put("name", departList.get(i).getName());
				list.add(map);					
			}	
			
			return list;
		}
		return null;
	}
	
	
}
